package com.jxc.action.rkgl;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.jxc.action.BaseAction;
import com.jxc.aop.LogInfoAop;
import com.jxc.model.vo.DataGrid;
import com.jxc.model.vo.Json;
import com.jxc.model.vo.SessionInfo;
import com.jxc.model.vo.VOrderlist;
import com.jxc.model.vo.VUser;
import com.jxc.service.OrderServiceI;
import com.jxc.util.ExceptionUtil;
import com.jxc.util.ResourceUtil;
import com.opensymphony.xwork2.ModelDriven;

@Namespace("/rkgl")
@Action(value = "orderAction", results = {
		@Result(name = "order", location = "/order/order.jsp"),
		@Result(name = "orderAdd", location = "/order/orderAdd.jsp"),
		@Result(name = "orderInfo", location = "/order/orderInfo.jsp") })
public class OrderAction extends BaseAction implements ModelDriven<VOrderlist> {
	private final static Logger logger = Logger.getLogger(OrderAction.class);
	@Autowired
	private OrderServiceI orderService;
	
	private VOrderlist model = new VOrderlist();
	private String items;
	@Override
	public VOrderlist getModel() {
		return model;
	}
	
	public String getItems() {
		return items;
	}
	public void setItems(String items) {
		this.items = items;
	}

	public String order() {
		getSubAuths("RKGL_RKGL");
		return "order";
	}
	public void noAuth_datagrid() {
		DataGrid subDg = orderService.datagrid(model);
		this.writeJson(subDg);
	}
	public String orderAdd() {
		return "orderAdd";
	}
	@LogInfoAop(info = "商品入库")
	public void add() {
		Json j = new Json();
		try {
			orderService.save(model,items);
			j.setMsg("添加成功！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("添加失败！");
			logger.info(ExceptionUtil.getExceptionMessage(e));
		}
		super.writeJson(j);
	}

	public void delete() {
		Json j = new Json();
		orderService.delete(model.getIds());
		j.setSuccess(true);
		j.setMsg("删除成功!");
		super.writeJson(j);
	}
	
	public String orderInfo(){
		getRequest().setAttribute("id", model.getId());
		return "orderInfo";
	}
	
	public void noAuth_checkOrder(){
		writeJson(orderService.search(model));
	}
	
	public void noAuth_checkItems(){
		writeJson(orderService.getItems(model));
	}
}
